<template>
  <div>
    我是萝莉组件{{masSun}} {{msg}} {{sss}}
    <el-button @click="sendData" type="primary">给父组件传值</el-button>
    <!--  -->
    <el-button @click="busFun" >给兄弟组件</el-button>
  </div>
</template>
<script>
// 在 vue组件中引入
import bus from '../utils/bus'
export default {
  data() {
    return {
      sss: '',
      masSun: this.msg,
      date: 'fsdf'
    }
  },
  // props: ['msg'],
  props: {
    msg: Number
  },
  created() {},
  methods: {
    init() {
      console.log(this.msg)
      this.masSun = this.masSun + 1
    },
    // 给父组件传值
    sendData() {
      // func是父组件传值绑定的函数,第二个参数是要传的值
      this.$emit('func', this.sss)
    },
    busFun() {
      // 通过 $emit 来触发方法，参数1 是定义方法名，参数2 是你要发送的数据
      bus.$emit('name', this.date)
    }
  },
  watch: {
    msg: {
      handler(newData, oldData) {
        this.sss = newData + 1
        this.sendData()
        console.log(newData, 'newData')
      },
      immediate: true,
      deep: true
    }
  }
}
</script>
<style lang="Less" scoped>
</style>
